import pymysql

class Longguo():
    def commect_database(self):
        # 连接数据库
        self.db = pymysql.connect(
            host='10.59.9.24',
            user='wms',
            password='Wms123456!',
            database='wms'
        )

        return self.db

    # 将数据以字典的形式打印出来
    def list_of_dicts(self, sql):
        # 创建游标
        cur = self.commect_database().cursor()
        # 输入sql语句
        cur.execute(sql)
        self.data = [dict((cur.description[i][0], value) for i, value in enumerate(row)) for row in cur.fetchall()]
        return self.data

if __name__ == '__main__':
    lg = Longguo()
    # lg.commect_database()
    platform_name = lg.list_of_dicts("SELECT platform_name FROM ba_platform ORDER BY create_date DESC LIMIT 1;")
    print(platform_name[0]["platform_name"])